﻿using System;
using System.Collections.Generic;
 
using System.Text;
using System.IO;
using System.ComponentModel;

namespace GGSharp.Http
{
    public abstract class HttpStructureBase : INotifyPropertyChanged
    {
        private RequestState _state = RequestState.Idle;

        public RequestState State
        {
            get { return _state; }
            set
            {
                if (_state != value)
                {
                    _state = value;
                    OnPropertyChanged("State");
                }
            }
        }

        public abstract void Read(StreamReader reader);
        //public abstract void Write(StreamWriter writer);

        private int getHttpHash(string[] hashParams)
        {
            int b = -1, i, j;
            uint a, c;

            if (hashParams.Length == 0)
                return -1;

            for (i = 0; i < hashParams.Length; i++)
            {
                for (j = 0; j < hashParams[i].Length; j++)
                {
                    c = hashParams[i][j];
                    a = (uint)(c ^ b) + (c << 8);
                    b = (int)(a >> 24) | (int)(a << 8);
                }
            }
            return System.Math.Abs(b);
        }

        protected int getHttpHash(string hashParams)
        {
            int b = -1, i, j;
            uint a, c;

            if (hashParams.Length == 0)
                return -1;

            for (i = 0; i < hashParams.Length; i++)
            {
                c = hashParams[i];
                a = (uint)(c ^ b) + (c << 8);
                b = (int)(a >> 24) | (int)(a << 8);
            }

            return System.Math.Abs(b);
        }


        #region INotifyPropertyChanged Members

        protected void OnPropertyChanged(string property)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(property));
        }

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
}
